// JScript source code
Main()
 
function Main()
{
    var intMax = 9;
    var sLocation = "chapter30";
    //dirListing("http://library.osu.edu/sites/rarebooks/ohio-mich/")
    sDestFolder = "x:\\temp\\" + sLocation + "\\";
    sSrcUrl = "http://library.osu.edu/sites/rarebooks/ohio-mich/images/legends_of_le_detroit/" + sLocation + "/"; 
    sContentTypeExpected = "image/jpeg"; 
    for(i = 1; i <= intMax; i++)
    {
        sImageFile = i + ".jpg"; 
        ImageStream(sDestFolder, sSrcUrl, sImageFile, sContentTypeExpected);
    }
}
    
function dirListing(sURL) 
{
    var oXML 

    oXML = CreateObject("msxml2.XMLHTTP") 
    oXML.Open("GET", sURL, false); //<==== no async call, so no need for a wait loop... 
    oXML.Send(null);
    dirListing = oXML.responseText;
    WScript.Echo(dirListing);
}

//'===DemoGetImageStream.vbs=== 
//' 
//'Requires: 
//' 
//' - XML 3.0 for "msxml2.ServerXMLHTTP" 
//' - ADO 2.5+ for "adodb.stream" 
//' 
//'============================ 
//'

function ImageStream(sDestFolder, sSrcUrl, sImageFile, sContentTypeExpected)
{
    var oHTTP;
    oHTTP = new ActiveXObject("MSXML2.XMLHTTP");
    //WScript.Echo(sSrcUrl + sImageFile); 
    oHTTP.open("GET", sSrcUrl + sImageFile, false); 
    oHTTP.send(null); 

    if (oHTTP.status != 200) 
    {
        WScript.Echo("unexpected status = " + oHTTP.status + oHTTP.statusText); 
        wscript.quit; 
    }

    sContentTypeReturned = oHTTP.getResponseHeader("content-type"); 

    if(sContentTypeReturned != sContentTypeExpected) 
    {
        WScript.Echo("unexpected content-type: " + sContentTypeReturned + " content-type expected: " + sContentTypeExpected); 
        WScript.Quit(); 
    }

    oStream = new ActiveXObject("ADODB.Stream"); 

    var adTypeBinary = 1; 
    var adSaveCreateOverWrite = 2; 
    oStream.Type = adTypeBinary; 
    oStream.Open(); 
    oStream.Write(oHTTP.responseBody);
    WScript.Echo(oHTTP.responseBody); 
    oStream.SaveToFile(sDestFolder + sImageFile, adSaveCreateOverWrite); 
    oStream = null; 
    oHTTP = null; 
    WScript.Echo("Done..."); 
}